package com.ocr.utils.impl;

import com.ocr.utils.IQuestionToResult;
import com.ssmfuse.Bean.Result;
import com.ssmfuse.domain.Question;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 化粪池堵塞的凶手
 */
public class QuestionToResultImpl implements IQuestionToResult {

    /**
     * 将Questionlist转换为Resultlist
     * @param questions
     * @return
     */
    public static List<Result> get(List<Question> questions) {
        List<Result> results = new ArrayList<>();
        for (Question question: questions) {
            Result result = new Result();
            result.setQuestion(question.getQuestion_name());
            result.setTijie(question.getQuestion_explain());
            result.setDaan(question.getQuestion_answer());
            results.add(result);
        }
        return results;
    }

    /**
     * 相似度比较 将questions中相似度大于bi的存入Result
     * @param questions
     * @param stringsum
     * @param bi
     * @return
     */
    public static List<Result> xiangSiGet(List<Question> questions,String stringsum,double bi){
        List<Result> results = new ArrayList<>();
        for (Question question: questions) {
            Result result = new Result();
            //用临时List比较相关性
            if (SimilarityUtil.getSimilarity(question.getQuestion_name(),stringsum)>bi){
                result.setQuestion(question.getQuestion_name());
                result.setTijie(question.getQuestion_explain());
                result.setDaan(question.getQuestion_answer());
                results.add(result);
            }
        }
        return results;
    }
}
